package com.wlr.blog.job;

import com.wlr.blog.web.common.utils.SpringContextUtils;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 定时任务工具类
 *
 * @author lrwang
 * @version 1.0
 * @date 2022/11/22 10:34
 */
@Component
public class QuartzUtils {
    public static void invoke(SysJob job) {
        String beanName = job.getBeanName();
        String methodName = job.getMethod();
        Object bean = SpringContextUtils.getBean(beanName);
        try {
            Method method = bean.getClass().getDeclaredMethod(methodName);
            method.invoke(bean);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
